package com.coderly.onlinegallerysharingplatform.controller;

import com.coderly.onlinegallerysharingplatform.common.convention.errorcode.ErrorCode;
import com.coderly.onlinegallerysharingplatform.common.response.Response;
import com.coderly.onlinegallerysharingplatform.model.dao.entity.SpaceDO;
import com.coderly.onlinegallerysharingplatform.model.dto.req.analyze.*;
import com.coderly.onlinegallerysharingplatform.model.dto.resp.analyze.*;
import com.coderly.onlinegallerysharingplatform.service.AnalyzeService;
import com.coderly.onlinegallerysharingplatform.toolkit.ExceptionTrowUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 系统数据分析控制器
 */
@RestController
@RequiredArgsConstructor
public class AnalyzeController {

    private final AnalyzeService analyzeService;

    /**
     * 获取空间使用分析
     */
    @PostMapping("/space/analyze/usage")
    public Response<SpaceUsageAnalyzeRespDTO> getSpaceUsageAnalyze(@RequestBody SpaceUsageAnalyzeReqDTO spaceUsageAnalyzeReqDTO) {
        ExceptionTrowUtils.throwIf(spaceUsageAnalyzeReqDTO == null, ErrorCode.PARAMS_ERROR);
        return Response.success(analyzeService.getSpaceUsageAnalyze(spaceUsageAnalyzeReqDTO));
    }

    /**
     * 获取空间图片分类分析
     */
    @PostMapping("/space/analyze/category")
    public Response<List<SpaceCategoryAnalyzeRespDTO>> getSpaceCategoryAnalyze(@RequestBody SpaceCategoryAnalyzeReqDTO spaceCategoryAnalyzeReqDTO) {
        ExceptionTrowUtils.throwIf(spaceCategoryAnalyzeReqDTO == null, ErrorCode.PARAMS_ERROR);
        return Response.success(analyzeService.getSpaceCategoryAnalyze(spaceCategoryAnalyzeReqDTO));
    }

    /**
     * 获取空间标签分析
     */
    @PostMapping("/space/analyze/tag")
    public Response<List<SpaceTagAnalyzeRespDTO>> getSpaceTagAnalyze(@RequestBody SpaceTagAnalyzeReqDTO spaceTagAnalyzeReqDTO) {
        ExceptionTrowUtils.throwIf(spaceTagAnalyzeReqDTO == null ,ErrorCode.PARAMS_ERROR);
        return Response.success(analyzeService.getSpaceTagAnalyze(spaceTagAnalyzeReqDTO));
    }

    /**
     * 获取空间标签分析
     */
    @PostMapping("/space/analyze/size")
    public Response<List<SpaceSizeAnalyzeRespDTO>> getSpaceSizeAnalyze(@RequestBody SpaceSizeAnalyzeReqDTO spaceSizeAnalyzeReqDTO) {
        ExceptionTrowUtils.throwIf(spaceSizeAnalyzeReqDTO == null ,ErrorCode.PARAMS_ERROR);
        return Response.success(analyzeService.getSpaceSizeAnalyze(spaceSizeAnalyzeReqDTO));
    }

    /**
     * 获取空间标签分析
     */
    @PostMapping("/space/analyze/user")
    public Response<List<SpaceUserAnalyzeRespDTO>> getSpaceUserAnalyze(@RequestBody SpaceUserAnalyzeReqDTO spaceUserAnalyzeReqDTO) {
        ExceptionTrowUtils.throwIf(spaceUserAnalyzeReqDTO == null ,ErrorCode.PARAMS_ERROR);
        return Response.success(analyzeService.getSpaceUserAnalyze(spaceUserAnalyzeReqDTO));
    }

    /**
     * 获取空间排名
     */
    @PostMapping("/space/analyze/rank")
    public Response<List<SpaceDO>> getSpaceRankAnalyze(@RequestBody SpaceRankAnalyzeReqDTO spaceRankAnalyzeReqDTO) {
        ExceptionTrowUtils.throwIf(spaceRankAnalyzeReqDTO == null ,ErrorCode.PARAMS_ERROR);
        return Response.success(analyzeService.getSpaceRankAnalyze(spaceRankAnalyzeReqDTO));
    }
    
    /**
     * 获取最近7天用户注册趋势
     */
    @PostMapping("/analyze/user/register/trend")
    public Response<List<TrendAnalyzeRespDTO>> getUserRegisterTrend() {
        return Response.success(analyzeService.getUserRegisterTrend());
    }
    
    /**
     * 获取最近7天图片上传趋势
     */
    @PostMapping("/analyze/picture/upload/trend")
    public Response<List<TrendAnalyzeRespDTO>> getPictureUploadTrend() {
        return Response.success(analyzeService.getPictureUploadTrend());
    }
}
